from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys


class TestCeshire:
    def setup_method(self, method):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
        self.driver.implicitly_wait(3)

    def teardown_method(self):
        self.driver.quit()

    # 用例标题
    def test_search(self):
        self.driver.get('https://ceshiren.com/')
        self.driver.find_element(By.ID, 'search-button').click()
        self.driver.find_element(By.ID, 'search-term').send_keys('Appium')
        self.driver.find_element(By.ID, 'search-term').send_keys(Keys.ENTER)
        self.driver.find_element(By.CSS_SELECTOR,
                                 '#ember7 > header > div > div > div.panel.clearfix > div > div > div > div > div.results > div > ul > li:nth-child(1) > a > span.topic > span.first-line > span.topic-title > span').click()
        ele_text = self.driver.find_element(By.CSS_SELECTOR, '#topic-title > div > div > h1 > a').text
        print(ele_text)
        assert ele_text == '关于Appium雪球元素定位出现的问题'
        assert "Appium" in ele_text
